<template>
  <div class="common-table-operations-component">
    <div class="left-actions">
      <div class="left-operations">
        <span v-if="selectedCount > 0" class="selected-count">
          {{ $t('common.selectedItems', { count: selectedCount }) }}
        </span>
        <a-space>
          <a-button type="primary" @click="handleAdd">
            <template #icon><PlusOutlined /></template>{{ $t('dict.addType') }}
          </a-button>
          <a-button danger :disabled="selectedCount === 0" @click="handleBatchDelete">
            <template #icon><DeleteOutlined /></template>{{ $t('common.batchDelete') }}
          </a-button>
          <a-button @click="handleExport">
            <template #icon><ExportOutlined /></template>{{ $t('dict.export') }}
          </a-button>
          <a-button @click="handleRefresh">
            <template #icon><ReloadOutlined /></template>{{ $t('common.refresh') }}
          </a-button>
        </a-space>
      </div>
    </div>
    <div class="right-actions">
      <a-space>
        <a-button type="primary" @click="handleSearch">
          <template #icon><SearchOutlined /></template>{{ $t('common.search') }}
        </a-button>
        <a-button @click="handleReset">
          <template #icon><UndoOutlined /></template>{{ $t('common.reset') }}
        </a-button>
      </a-space>
    </div>
  </div>
</template>

<script lang="ts" setup>
defineOptions({
  name: 'TypeTableOperations'
})

withDefaults(defineProps<{
  selectedCount: number
}>(), {
  selectedCount: 0
})

// Emits定义
const emit = defineEmits<{
  (e: 'add'): void
  (e: 'batch-delete'): void
  (e: 'export'): void
  (e: 'refresh'): void
  (e: 'search'): void
  (e: 'reset'): void
}>()

// 添加
const handleAdd = () => {
  emit('add')
}

// 批量删除
const handleBatchDelete = () => {
  emit('batch-delete')
}

// 导出
const handleExport = () => {
  emit('export')
}

// 刷新
const handleRefresh = () => {
  emit('refresh')
}

// 搜索
const handleSearch = () => {
  emit('search')
}

// 重置
const handleReset = () => {
  emit('reset')
}
</script>

<style lang="scss" scoped>
@import '@/assets/styles/views/common.scss';
</style>